package client.network.interactive;

import message.Message;
import message.types.stalkerstring.GetUserFromNameAnswer;
import stalker.Stalker;
import client.network.ServiceRequestCenter;

public class InviteUserByNameRequest implements InteractiveRequest {
  
  private Stalker room_;
  private String username_;
  
  public InviteUserByNameRequest(Stalker room, String username) {
    assert (room != null && username != null);
    room_ = room;
    username_ = username;
  }
  
  public boolean getReply(ServiceRequestCenter servicer, Message message) {
    if (message instanceof GetUserFromNameAnswer) {
      GetUserFromNameAnswer answer = (GetUserFromNameAnswer)message;
      if (answer.getName().equals(username_)) {
        servicer.inviteToRoom(answer.getCredential(), room_);
        return true;
      }
    }
    return false;
  }

  public void startRequest(ServiceRequestCenter servicer) {
    servicer.requestUserFromName(username_);
  }

}
